package cn.tedu.restfultest;


import cn.tedu.pojo.CarRestful;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("restful")
@CrossOrigin//解决JS跨域问题
public class RestfulTest {

    @RequestMapping("data")
    public String get(){
        System.out.println("试一下就知道了");
        return "12345";
    }
        @RequestMapping("data1")//直接传参数获取值
        public CarRestful get1(){//@RequestBody String jsonString(json串传输)？？？
            CarRestful c=new CarRestful();
            c.setId(100);
            c.setPrice(19.9);
            return c;
        }
        @RequestMapping("data2")//get获取数据方式
        public String get2(Integer id,String name,Double price){
            return id+name+price;
        }
        //优化get提交数据的方式restful:http://localhost:8080/car/add2/10/bmw/9.9
        @RequestMapping("data3/{id}/{name}/{price}")//{id}是占位符，表示这个参数的位置
        public void get3(@PathVariable Integer id,//@PathVariable用来获取{}中间的值
                         @PathVariable String name,//@PathVariable用来获取{}中间的值
                         @PathVariable Double price){//@PathVariable用来获取{}中间的值
            System.out.println(id+name+price);
        }

}
